import serial
import threading
import time

x = serial.Serial('com3', 115200)
# i=0
# def send():
# while True:
# print("wocao")
# myinput=input('shuru>')
# myinput=myinput.encode(encoding="utf-8")
# print("you input "+myinput)
# time.sleep(1)
# x.write(myinput)


def receive():
    myout = ""
    while True:
        while x.inWaiting() > 0:
            try:
                myout += x.readline().decode()
            except Exception as err:
                print(err)
            if myout != "":
                print(myout)
                myout = ""
        # time.sleep(1)


if __name__ == '__main__':
    t1 = threading.Thread(target=receive, name="receive")
    # t2= threading.Thread(target=fasong, name="fasong")
    # t2.start()
    t1.start()
